﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common.DBOper
{
    public class Cls_RunSet
    {
        public long TestId;
        public string BandWidth;
        public string SpecLines;
        public string Resolution;
        public string NumAverage;
        public string AverageModel;
        public string WindowFun;

  

    }

    public class OperRunSet 
    {

        public int AddRunSet(Cls_RunSet cls_runset) 
        {
            int i = 0;
            string connString = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0} ;Persist Security Info=False;Jet OLEDB:Database Password={1}", Mdl_Class.FilePath, Mdl_Class.AccessPassWord);
            using (MyDb_Access mydb = new MyDb_Access(connString))
            {
                try
                {
                    mydb.Open();
                    string sql = string.Format("insert into T_RunSet(TestId,BandWidth,SpecLines,Resolution,NumAverage,AverageModel,WindowFun) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')",
                        cls_runset.TestId,
                       cls_runset.BandWidth,
                       cls_runset.SpecLines,
                       cls_runset.Resolution,
                       cls_runset.NumAverage,
                       cls_runset.AverageModel,
                       cls_runset.WindowFun);
                    i = mydb.ExecuteNonQuery(sql);
                    mydb.Close();
                }
                catch (Exception ex)
                {
                    Mdl_Class.WriteLog.dbErrLog("AddRunSet(Cls_RunSet cls_runset)", ex.ToString());
                }
            }
            return i;
        }


        public Cls_RunSet GetRunSet(string testId) 
        {
            Cls_RunSet clsrunset = null;
            string connString = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0} ;Persist Security Info=False;Jet OLEDB:Database Password={1}", Mdl_Class.FilePath, Mdl_Class.AccessPassWord);
            using (MyDb_Access mydb = new MyDb_Access(connString))
            {
                try
                {
                    mydb.Open();
                    string sql = string.Format("select * from T_RunSet  where TestId='{0}'", testId);
                    mydb.ExecuteReader(sql);
                    if (mydb.DataReader.Read())
                    {
                        clsrunset = new Cls_RunSet();
                    
                        clsrunset.TestId = Convert.ToInt64(mydb.DataReader["TestId"]);
                        clsrunset.BandWidth =mydb.DataReader["BandWidth"].ToString();
                        clsrunset.SpecLines = mydb.DataReader["SpecLines"].ToString();
                        clsrunset.Resolution = mydb.DataReader["Resolution"].ToString();
                        clsrunset.NumAverage = mydb.DataReader["NumAverage"].ToString();
                        clsrunset.AverageModel = mydb.DataReader["AverageModel"].ToString();
                        clsrunset.WindowFun = mydb.DataReader["WindowFun"].ToString();

                    }

                    mydb.Close();
                }
                catch (Exception ex)
                {
                    clsrunset = null;
                    Mdl_Class.WriteLog.dbErrLog("GetRunSet(string testId) ", ex.ToString());
                }

                return clsrunset;
            }
        }
    }
}
